﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace iseeqq
{
    public class QQValue
    {
        /// <summary>
        /// QQ 用户信息存储目录
        /// </summary>
        public static string tencentFile = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Tencent Files/All Users";



        /// <summary>
        /// QQ 启动程序路径
        /// </summary>
        public static QQInfo qqInfo = getQqProcPath();

        public struct QQInfo
        {
            public string qqProcPath;
            public string username;
            public string password;

        }

        static QQInfo getQqProcPath()
        {
            //WritePrivateProfileString("QQ", "Tencent", @"C:\Program Files (x86)\Tencent\QQ\Bin\QQScLauncher.exe", "D:\\demo.ini");

            StringBuilder temp = new StringBuilder(255);
            GetPrivateProfileString("QQ", "Tencent", "", temp, 255, @"./App.ini");
            QQInfo qq = new QQInfo();
            qq.qqProcPath = temp.ToString();
            GetPrivateProfileString("QQ", "username", "", temp, 255, @"./App.ini");
            qq.username = temp.ToString();
            GetPrivateProfileString("QQ", "password", "", temp, 255, @"./App.ini");
            qq.password = temp.ToString();

            return qq;
        }

        [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
        private static extern bool WritePrivateProfileString(
            string lpAppName, string lpKeyName, string lpString, string lpFileName);

        [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
        private static extern int GetPrivateProfileString(
            string lpAppName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString,
            int nSize, string lpFileName);

    }
}
